<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateCustomersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('customers', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name', 20)->index()->unique();
            $table->tinyInteger('sex')->default(1)->comment('1:男,2:女');
            $table->tinyInteger('type')->default(1)->comment('角色模板');
            $table->string("password", 100);
            $table->decimal("money", 18, 0)->default(0)->comment('金额');
            $table->tinyInteger('status')->default(1)->comment('1:激活,2:无效');
            $table->tinyInteger('goods_vip')->default(0)->comment('购买vip');
            $table->softDeletes();
            $table->timestamps();
        });
        Schema::create('goods', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name', 20)->index();
            $table->integer('price');
            $table->integer('amount')->default(0)->comment('数量.0:不限量');
            $table->tinyInteger('limit_amount')->default(1)->comment('限购数量');
            $table->dateTime('start_time')->nullable()->comment('开售时间');
            $table->softDeletes();
            $table->timestamps();
        });
        Schema::create('carts', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->bigInteger('cus_id')->index();
            $table->bigInteger('goods_id')->index();
            $table->integer('amount')->index();
            $table->softDeletes();
            $table->timestamps();
        });
        Schema::create('buy_logs', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->bigInteger('cus_id')->index();
            $table->bigInteger('goods_id')->index();
            $table->integer('amount')->index();
            $table->softDeletes();
            $table->timestamps();
        });

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('customers');
        Schema::dropIfExists('goods');
        Schema::dropIfExists('cart');
        Schema::dropIfExists('buy_logs');
    }
}
